<?php
class a_widgetService extends Service{
	//要加缓存
	public function __construct(){
		parent::__construct();
		
		$this->virtual_pjt=load_pjt(1);
		$this->cache_dir=$this->virtual_pjt['PROJECT_PATH'].'runtime/widget_cache';
		$this->cache_time=3600*24;
		
		$this->table_cate=table('category');
		$this->table=table('arc');
		$this->table_data=table('arc_data');
		$this->table_attrtag=table('attrtaglist');
		$this->table_wordtag=table('wordtaglist');
		$this->table_index_1=table('index_1');
		$this->table_index_2=table('index_2');
		
	}
	//按点击数取的热门属性标签
	public function hot_attrtags($num=10){
		$query="select `id`,`tag` from `{$this->table_index_1}` order by `hits` desc limit {$num}";
		$db_cache=new db_cache($this->cache_dir,$query,$this->cache_time);
		$info=$db_cache->action('r');
		if(!$info){
			$info=$this->m->mselect($query);
			$db_cache->action('w',$info);
		}
		return $info;
	}
	//右侧热门标签
	public function hot_wordtags($num=10){
		$query="select `id`,`tag` from `{$this->table_index_2}` order by `hits` desc limit {$num}";
		$db_cache=new db_cache($this->cache_dir,$query,$this->cache_time);
		$info=$db_cache->action('r');
		if(!$info){
			$info=$this->m->mselect($query);
			$db_cache->action('w',$info);
		}
		return $info;
	}
	//右侧热点文章
	public function hot_article($num=10){
		$query="select `id`,`title`,`htmlurl`,`add_time` from `{$this->table}` where `status`='1' order by `hits` desc limit {$num}";
		$db_cache=new db_cache($this->cache_dir,$query,$this->cache_time);
		$info=$db_cache->action('r');
		if(!$info){
			$info=$this->m->mselect($query);
			$db_cache->action('w',$info);
		}
		return $info;
	}
	//右侧推荐文章
	public function cmd_article($num=10){
		$query="select `id`,`title`,`htmlurl`,`add_time` from `{$this->table}` where `status`='1' and `flag`='2' order by `add_time` desc limit {$num}";
		$db_cache=new db_cache($this->cache_dir,$query,$this->cache_time);
		$info=$db_cache->action('r');
		if(!$info){
			$info=$this->m->mselect($query);
			$db_cache->action('w',$info);
		}
		return $info;
	}
//	
}